﻿using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;

namespace DYSales.Views.sys
{
    public partial class setBase_page : Page
    {
        public setBase_page()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(setBase_page_Loaded);
            bt_保存.Click += new RoutedEventHandler(bt_保存_Click);
        }

        void bt_保存_Click(object sender, RoutedEventArgs e)
        {
            var dt = g_dataform.DataContext as Web.Set_table;
            if (!dt.HasValidationErrors)
            {
                bt_保存.IsEnabled = false;
                dm.getDS().SubmitChanges(lo =>
                {
                    bt_保存.IsEnabled = true;
                }, null);
            }
        }

        void setBase_page_Loaded(object sender, RoutedEventArgs e)
        {
            dm.getDS().Load(dm.getDS().GetSet_tablesQuery(), lo =>
            {
                if (!lo.HasError && lo.Entities.Count() > 0)
                {
                    g_dataform.DataContext = lo.Entities.First();
                }
            }, null);
            tb.Focus();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

    }
}
